# 字符串编码转换
# str = "wandaixin"
# a1 = str.encode()
# print("编码后：", a1, type(a1))
# a2 = a1.decode()
# print("解码后：", a2, type(a2))

# str2 = "练习"
# s1 = str2.encode("utf-8")
# print(s1, type(s1))
# s2 = s1.decode("utf-8")
# print(s2, type(s2))

# 字符串操作
# 字符串拼接 +
# name1 = "字符串"
# name2 = "操作"
# name = name1 + name2
# print(name)
# 字符串重复 *
# print("https " * 5)

# 成员运算符
# in 如果包含返回 True
# not in 如果不包含返回 True
# witcher = "witcher"
# print('witch' in witcher)    #True
# print('x' not in witcher)     #True

#下标（索引）
# index = "index"
# for i in range(0, 5):
#     print(index[i])
# 从右往左数
# i = -1;
# while i >= -5:
#     print(index[i])
#     i -= 1;

# 切片  包前不包后
# st[开始位置:结束位置:步长]
# st = "abcdefghijk"
# print(st[3:5])    #->de
# print(st[5:])     #->fghijk
# print(st[:4])     #->abcd
# print(st[1::2])     #->bdfhj
# print(st[::-1])    #反转
# 从右往左
# print(st[-5:])      #->ghijk
# print(st[:-5])      #->abcdef
# print(st[-5::-1])   #->gfedcba  反着切

# 查找元素find
# 检测子字符串是否包含在字符串中,如果存在就返回这个子字符串开始的下边,不存在返回-1
# find(子字符串,开始下标,结束下标)
# print("string".find('t'))
# print("string".find('ring'))

# index  与find区别在于不存在子字符串就会报错
# print("string".index('t'))
# print("string".index('x'))

# count 子字符串在字符串中出现的次数
# str1 = "abababababac"
# print(str1.count('aba'))

# 判断
# stratswith() 是否以某个子字符串开头,是返回True,设置开始和结束位置则在指定位置中查找
# str = "kangaroo"
# print(str.startswith("gar", 3, 8))
# endswith() 是否以某个字符串结尾,是返回True,设置开始和结束位置则在指定位置中查找
# str = "kangaroo"
# print(str.endswith("oo", 5, 8))

# isupper()  检测字符串中所有的字母是否都为大写,
# str = "KANGAROO"
# print(str.isupper())

# replace() 替换  默认全部替换
# replace(旧,新,替换次数)
# str = "我要吃饭吃饭"
# print(str.replace("吃饭","睡觉",1))

# split() 分割
# str = "abcdbcda"
# print(str.split("c"))
# print(str.split("bc"))

# capitalize() 第一个字幕大写,其他都小写
# str = "kangarOO"
# print(str.capitalize())

# lower() 大写字母转为小写
# str = "KangarOO"
# print(str.lower())

# upper() 小写字母转为大写
# str = "KangarOO"
# print(str.upper())


